import { useEffect, useState } from 'react'
import { Avatar, Card, Col, Row } from 'antd'
import style from './index.less'
import { useSelector } from 'react-redux'
export default function Home() {
    const common = useSelector((state: any) => state.common)
    const [state] = useState<tenantHomeData>({ companyCount: "", companyList: [], gzcList: [], itemCount: '', itemVOS: [] })
    const [logList] = useState<logItem[]>([])
    const avatar = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'
    //判断时间是早上中文还是晚上
    function getTime() {
        let time = new Date().getHours()
        if (time <= 5) {
            return '凌晨好'
        }
        if (time <= 10) {
            return '早上好'
        }
        if (time <= 13) {
            return '中午好'
        }
        if (time <= 17) {
            return '下午好'
        }
        if (time <= 19) {
            return '傍晚好'
        }
        if (time <= 22) {
            return '晚上好'
        }
        if (time <= 24) {
            return '深夜好'
        }
    }

    async function gettenantHomeApi() {
        // let res = await gettenantHome()
        // setstate(res.data)
    }
    useEffect(() => {
        gettenantHomeApi()
        getTime()
        // if (common.loginInfo.userType == 1) {
        //     logPageItemApi()
        // }
        return
    }, [])
    return (
        <div className={style.homeWrap}>
            {
                common.loginInfo.userType == 1 ? <>
                    <div className={style.homeTopWrap}>

                        <h2>工作台</h2>
                        <div className={style.homeTop}>
                            <div className={style.homeTopLeft}>
                                <Avatar size="large" className={style.homeTopLeftImg} src={common.loginInfo.userIconUrl || avatar} />
                                <div className={style.homeTopLeftRight}>
                                    <div className={style.homeTopLeftRightName}>{getTime()}，{common.loginInfo.trueName}!</div>
                                    <div>上次登录时间：{common.loginInfo.loginTime}</div>
                                </div>
                            </div>
                            <div className={style.homeTopRight}>
                                <div className={style.extraContent}>
                                    <div className={style.statItem}>
                                        <p>项目登记总数</p>
                                        <p className={style.content}>{state.itemCount}</p>
                                    </div>
                                    <div className={style.statItem}>
                                        <p>开发商总数</p>
                                        <p className={style.content}> {state.companyCount} </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div className={style['ant-pro-page-container-children-content']}>
                        <Row>
                            <Col span={16} style={{ paddingLeft: "12px", paddingRight: "12px" }}>
                                <Card title="登记项目" extra={<a href="#/project">+ 所有项目</a>} >
                                    {
                                        state.itemVOS?.map((item, index) =>
                                            <Card.Grid style={{
                                                width: '33.33%',
                                            }} className={style.CardItem} key={index}>
                                                <p className={style.cardName}>{item.itemName}</p>
                                                <p className={style.cardtime}>登记起止时间:</p>
                                                <p className={style.cardtime}>{item.surveyStartTime}</p>
                                                <p className={style.cardtime}>{item.surveyEndTime}</p>
                                                <p className={style.cardcompany}>{item.companyName || "暂无开发商"}</p>
                                            </Card.Grid>
                                        )
                                    }
                                </Card>
                                <Card title="操作日志" extra={<a href="#/logList">+ 操作日志</a>} >
                                    {
                                        logList.map((item, index) =>
                                            <Card.Grid style={{
                                                width: '100%',
                                            }}
                                                className={style.logCardItem} key={index}>
                                                <Avatar size="large" className={style.homeTopLeftImg} src={avatar} />
                                                <div className={style.logCardItemRight}>
                                                    <p className={style.cardName}>{item.actContent}</p>
                                                    <p className={style.cardcompany}>{item.createTime}</p>
                                                </div>
                                            </Card.Grid>
                                        )
                                    }
                                </Card>
                            </Col>
                            <Col span={8} style={{ paddingLeft: "12px", paddingRight: "12px" }}>
                                <Card title="开发商" extra={<a href="#/companyList">+ 开发商</a>} >
                                    {
                                        state.companyList?.map((item, index) =>
                                            <Card.Grid style={{
                                                width: '50%',
                                            }} className={style.devlopersCardItem} key={index}>
                                                <img src={item.logoUrl || avatar} alt='' />
                                                <p className={style.cardName}>{item.bizName}</p>
                                            </Card.Grid>
                                        )
                                    }
                                </Card>
                                <Card title="公证处" extra={<a href="#/gzcList">+ 公证处</a>} style={{ marginTop: "20px" }} >
                                    {
                                        state.gzcList?.map((item, index) =>
                                            <Card.Grid style={{
                                                width: '50%',
                                            }} className={style.devlopersCardItem} key={index}>
                                                <img src={item.logoUrl || avatar} alt='' />
                                                <p className={style.cardName}>{item.bizName}</p>
                                            </Card.Grid>
                                        )
                                    }
                                </Card>
                            </Col>
                        </Row>
                    </div>
                </> :
                    <div className={style.gzcOrCompanyHomeWrap}>
                        <Avatar size="large" className={style.homeTopLeftImg} src={common.loginInfo.userIconUrl || avatar} />
                        <div className={style.homeTopLeftRight}>
                            <div className={style.homeTopLeftRightName}>欢迎进入云登记运营管理后台</div>
                            <div>上次登录时间：{common.loginInfo.loginTime}</div>
                            <div className={style.statItem}>
                                <p className={style.content}>{state.itemCount}</p>
                                <p>登记项目总数</p>
                            </div>
                        </div>
                    </div>
            }
        </div>
    )
}